using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class PaydetMap : EntityTypeConfiguration<Paydet>
    {
        public PaydetMap()
        {
            // Primary Key
            this.HasKey(t => t.PAYDET_ID);

            // Properties
            this.Property(t => t.PAYREF)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.ARREF)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.INVNO)
                .HasMaxLength(8);

            this.Property(t => t.DESCR)
                .HasMaxLength(100);

            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Paydet");
            this.Property(t => t.PAYDET_ID).HasColumnName("PAYDET_ID");
            this.Property(t => t.PAYREF).HasColumnName("PAYREF");
            this.Property(t => t.ARREF).HasColumnName("ARREF");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.PDTODAY).HasColumnName("PDTODAY");
            this.Property(t => t.PDTODAYDOL).HasColumnName("PDTODAYDOL");
            this.Property(t => t.DISCOUNT).HasColumnName("DISCOUNT");
            this.Property(t => t.DISCOUNTD).HasColumnName("DISCOUNTD");
            this.Property(t => t.DESCR).HasColumnName("DESCR");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.PDTODAYACT).HasColumnName("PDTODAYACT");
            this.Property(t => t.DISCOUNTA).HasColumnName("DISCOUNTA");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.Batchttl)
                .WithMany(t => t.Paydets)
                .HasForeignKey(d => d.BATCH);
            this.HasRequired(t => t.Payment)
                .WithMany(t => t.Paydets)
                .HasForeignKey(d => d.PAYREF);

        }
    }
}
